
//todo
// 假设有k个人质和k个绑匪围成一圈。人质的编号从1到k，绑匪的编号从k+1到2k。
// 从编号1开始，每次从其中选出第m个人(隔m-1选出一人)出列。
// 希望求出m的最小值，使得最先出列的k个人都是绑匪，即都是编号从k+1到2k的人。
#include "iostream"
#include "vector"
#include "unordered_map"
#include "algorithm"

struct Pos {
    int x;
    int y;

    Pos(int x, int y) : x(x), y(y) {

    }

    Pos() {}
};

struct PosOperator {
private:
    int width;
    Pos p;
public:
    PosOperator(int w, Pos p1) {
        width = w;
        p = p1;
    }

    PosOperator &rotate90() {
        auto y = p.y;
        p.y = p.x;
        p.x = width - y-1;
        return *this;
    }

    PosOperator &mirror() {
        p.y = width - p.y - 1;

        return *this;
    }

    Pos get() {
        return p;
    }
};

class Solution {
public:
    void handle(int n) {
        resize(n);
        input();
        auto a = analyze();
        printf("%d\n", a);
    }

private:
    int width;
    std::vector<std::vector<char>> af;
    std::vector<std::vector<char>> bf;
#define itermatch(_a_, _ret_){ \
    match= true;                    \
    for(int i=0;i<width;i++){\
        for(int j=0;j<width;j++){\
            Pos p(i,j);\
            PosOperator op(width,p);\
            _a_\
            if(af[p2.x][p2.y]!=bf[p.x][p.y]){\
                match=false;\
            }\
        }\
    }                         \
    if (match) {\
        return _ret_;\
    }                             \
}

    int analyze() {
        bool match;
        itermatch(auto p2 = op.rotate90().rotate90().rotate90().get();,1)
        //2
        itermatch(auto p2 = op.rotate90().rotate90().get();, 2)
        //3
        itermatch(auto p2 = op.rotate90().get();, 3)
        //4
        itermatch(auto p2 = op.mirror().get();, 4)
        //5
        itermatch(auto p2 = op.mirror().rotate90().get();, 5)
        itermatch(auto p2 = op.mirror().rotate90().rotate90().get();, 5)
        itermatch(auto p2 = op.mirror().rotate90().rotate90().rotate90().get();, 5)
        //6
        itermatch(auto p2 = op.get();, 6)

        return 7;
    }

    void input() {
        auto n = width;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                char a = getchar();
                while (a != '@' && a != '-') {
                    a = getchar();
                }
                bf[i][j] = a;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                char a = getchar();
                while (a != '@' && a != '-') {
                    a = getchar();
                }
                af[i][j] = a;
            }
        };
    }

    void resize(int n) {
        width = n;
        af.resize(n);
        bf.resize(n);
        for (auto &a:af) {
            a.resize(n);
        }
        for (auto &a:bf) {
            a.resize(n);
        }

    }
};

int main() {
    int i = 0;
    while (std::cin >> i) {
        Solution s;
        s.handle(i);
    }
    return 0;
}

